{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Number of Distinct Averages"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #two-pointers #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #双指针 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: distinctAverages"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #不同的平均值数目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个下标从 <strong>0</strong>&nbsp;开始长度为 <strong>偶数</strong>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;。</p>\n",
    "\n",
    "<p>只要&nbsp;<code>nums</code> <strong>不是</strong>&nbsp;空数组，你就重复执行以下步骤：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>找到&nbsp;<code>nums</code>&nbsp;中的最小值，并删除它。</li>\n",
    "\t<li>找到&nbsp;<code>nums</code>&nbsp;中的最大值，并删除它。</li>\n",
    "\t<li>计算删除两数的平均值。</li>\n",
    "</ul>\n",
    "\n",
    "<p>两数 <code>a</code>&nbsp;和 <code>b</code>&nbsp;的 <strong>平均值</strong>&nbsp;为&nbsp;<code>(a + b) / 2</code>&nbsp;。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>比方说，<code>2</code>&nbsp;和&nbsp;<code>3</code>&nbsp;的平均值是&nbsp;<code>(2 + 3) / 2 = 2.5</code>&nbsp;。</li>\n",
    "</ul>\n",
    "\n",
    "<p>返回上述过程能得到的 <strong>不同</strong>&nbsp;平均值的数目。</p>\n",
    "\n",
    "<p><strong>注意</strong>&nbsp;，如果最小值或者最大值有重复元素，可以删除任意一个。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>nums = [4,1,4,0,3,5]\n",
    "<b>输出：</b>2\n",
    "<strong>解释：</strong>\n",
    "1. 删除 0 和 5 ，平均值是 (0 + 5) / 2 = 2.5 ，现在 nums = [4,1,4,3] 。\n",
    "2. 删除 1 和 4 ，平均值是 (1 + 4) / 2 = 2.5 ，现在 nums = [4,3] 。\n",
    "3. 删除 3 和 4 ，平均值是 (3 + 4) / 2 = 3.5 。\n",
    "2.5 ，2.5 和 3.5 之中总共有 2 个不同的数，我们返回 2 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>nums = [1,100]\n",
    "<b>输出：</b>1\n",
    "<strong>解释：</strong>\n",
    "删除 1 和 100 后只有一个平均值，所以我们返回 1 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 &lt;= nums.length &lt;= 100</code></li>\n",
    "\t<li><code>nums.length</code>&nbsp;是偶数。</li>\n",
    "\t<li><code>0 &lt;= nums[i] &lt;= 100</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [number-of-distinct-averages](https://leetcode.cn/problems/number-of-distinct-averages/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [number-of-distinct-averages](https://leetcode.cn/problems/number-of-distinct-averages/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[4,1,4,0,3,5]', '[1,100]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        seen = set()\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i < j:\n",
    "            seen.add(nums[i] + nums[j])\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return len(seen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        n = len(nums)\n",
    "        s = set()\n",
    "        for i in range(n//2):\n",
    "            s.add((nums[i] + nums[-1-i]) / 2)\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        temp=[]\n",
    "        k=len(nums)\n",
    "        for i in range(k//2):\n",
    "            temp.append(nums[i]+nums[-1-i])\n",
    "        return len(set(temp))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        n = len(nums)\n",
    "        i, j = 0, n-1\n",
    "        ans = set()\n",
    "        while i < j:\n",
    "            ans.add(nums[i]+nums[j])\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def get_min_max(self,nums: List[int]) -> List[int]:\n",
    "        min = 0\n",
    "        max = 0\n",
    "        for index in range(1,len(nums)):\n",
    "            if nums[index] < nums[min]:\n",
    "                min = index\n",
    "            elif nums[index] > nums[max]:\n",
    "                max = index\n",
    "        return [min,max]\n",
    "\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        if nums:\n",
    "            if len(nums) == 2:\n",
    "                return 1\n",
    "            array = {}\n",
    "            while len(nums) >1:\n",
    "                arr = self.get_min_max(nums)\n",
    "                min = nums[arr[0]]\n",
    "                max = nums[arr[1]]\n",
    "                if min == max:\n",
    "                    nums.remove(min)\n",
    "                else:\n",
    "                    nums.remove(min)\n",
    "                    nums.remove(max)\n",
    "                pingjun = (min+max)/2\n",
    "                array[pingjun] = 1\n",
    "            return len(array)\n",
    "        else:\n",
    "            return 0\n",
    "                \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        avg_list = []\n",
    "        while nums:\n",
    "            min_num = min(nums)\n",
    "            max_num = max(nums)\n",
    "            avg = (min_num + max_num) / 2\n",
    "            avg_list.append(avg)\n",
    "            del nums[nums.index(min_num)]\n",
    "            del nums[nums.index(max_num)]\n",
    "        return len(set(avg_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        n =len(nums)\n",
    "        y=0\n",
    "        sum=[]\n",
    "        nums.sort()\n",
    "        while n>1:\n",
    "            S=(nums[y]+nums[n-1])/2\n",
    "            y=y+2\n",
    "            sum.append(S)\n",
    "            n=n-2\n",
    "        sum=set(sum)\n",
    "        d=len(sum)\n",
    "        return d    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        idx = len(nums)//2\n",
    "        return len(set(nums[i]+nums[-i-1] for i in range(idx)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        s = set()\n",
    "        while len(nums) != 0:\n",
    "            m = max(nums)\n",
    "            n = min(nums)\n",
    "            nums.pop(nums.index(m))\n",
    "            nums.pop(nums.index(n))\n",
    "            s.add((m+n)/2)\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        if len(nums)==2:\n",
    "            return 1\n",
    "        nums.sort()\n",
    "        A = []\n",
    "        while(1):\n",
    "            A.append(nums[0]+nums[-1])\n",
    "            nums = nums[1:-1]\n",
    "            \n",
    "            if len(nums) == 0:\n",
    "                break\n",
    "        return len(set(A))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        sol = set()\n",
    "        nums.sort()\n",
    "        i, j = 0, len(nums)-1\n",
    "        while i < j:\n",
    "            sol.add(nums[i] + nums[j])\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return len(sol)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        results = []\n",
    "        while len(nums) > 1:\n",
    "            avg = (nums[0] + nums[-1]) / 2\n",
    "            if avg not in results:\n",
    "                results.append(avg)\n",
    "            nums = nums[1:-1]\n",
    "        return len(results)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        ans = []\n",
    "        while len(nums)>0:\n",
    "            minnum = min(nums)\n",
    "            minindex = nums.index(minnum)\n",
    "            del nums[minindex]\n",
    "            maxnum = max(nums)\n",
    "            maxindex = nums.index(maxnum)\n",
    "            del nums[maxindex]\n",
    "            ans.append((maxnum+minnum)/2)\n",
    "        return len(set(ans))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        ans=[]\n",
    "        for i in range(0,len(nums)//2):\n",
    "            avg=(nums[i]+nums[len(nums)-i-1])/2\n",
    "            ans.append(avg)\n",
    "        ans.sort()\n",
    "        count =0\n",
    "        for i in range(0,len(ans)-1):\n",
    "            if ans[i]!=ans[i+1]:\n",
    "                count+=1       \n",
    "        return count+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        res=[]\n",
    "        nums.sort()\n",
    "        for i in range(int(len(nums)/2)):\n",
    "            res.append((nums[i]+nums[-i-1])/2)\n",
    "        return len(set(res))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        res = set()\n",
    "        n = len(nums)\n",
    "        nums.sort()\n",
    "        for i in range(n//2):\n",
    "            res.add((nums[n - i - 1] + nums[i]) / 2)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        set1 = set()\n",
    "        i = 0\n",
    "        j = len(nums) - 1\n",
    "        while i < j:\n",
    "            set1.add(nums[i] + nums[j])\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return len(set1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        n = set()\n",
    "        nums.sort()\n",
    "        while nums:\n",
    "            n.add((nums[0] + nums[-1]) / 2)\n",
    "            nums = nums[1:-1]\n",
    "        return len(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        ans = set()\n",
    "        i, j = 0, len(nums)-1\n",
    "        while i < j:\n",
    "            ans.add((nums[i]+nums[j]))\n",
    "            i+=1\n",
    "            j-=1\n",
    "        return len(ans)\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        result_set=set()\n",
    "        while len(nums)>1:\n",
    "            maxx=max(nums)\n",
    "            minn=min(nums)\n",
    "            nums.remove(maxx)\n",
    "            nums.remove(minn)\n",
    "            average=(maxx+minn)/2\n",
    "            result_set.add(average)\n",
    "        return len(result_set)\n",
    "         \n",
    "        \n",
    "                  \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        s = set()\n",
    "        nums.sort()\n",
    "        i = 0\n",
    "        j = len(nums)-1\n",
    "        while i < j:\n",
    "            s.add((nums[i]+nums[j])/2)\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        idx = len(nums)//2\n",
    "        return len(set(nums[i]+nums[-i-1] for i in range(idx)))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        hashTable = set()\n",
    "        nums.sort()\n",
    "        for i in range(len(nums) // 2):\n",
    "            a = nums[i]\n",
    "            b = nums[-1-i]\n",
    "            hashTable.add((a + b) / 2)\n",
    "        return len(hashTable)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums = sorted(nums)\n",
    "        s = set()\n",
    "        left = 0\n",
    "        right = len(nums) - 1\n",
    "        while left < right:\n",
    "            avg = (nums[left] + nums[right]) / 2\n",
    "            s.add(avg)\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        return len(s)\n",
    "        if left == right:\n",
    "            return 1\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        diff_set = set()\n",
    "        l = len(nums)\n",
    "        left, right = 0, l-1\n",
    "        while left < right:\n",
    "            diff_set.add((nums[left]+nums[right])/2)\n",
    "            left += 1\n",
    "            right -= 1 \n",
    "        return len(diff_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        s = set()\n",
    "        while nums:\n",
    "            a = nums.pop()\n",
    "            b = nums.pop(0)\n",
    "            s.add(a+b)\n",
    "        return len(s)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        left=0\n",
    "        right=len(nums)-1\n",
    "        averages={}\n",
    "\n",
    "        while left<=right:\n",
    "            average=(nums[left]+nums[right])/2\n",
    "            averages[average]=averages.get(average,0)+1\n",
    "            left+=1\n",
    "            right-=1\n",
    "        \n",
    "        print(averages)\n",
    "        \n",
    "        return len(averages)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        seen = set()\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i < j:\n",
    "            seen.add(nums[i] + nums[j])\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return len(seen)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        avgs = []\n",
    "        while len(nums) > 0:\n",
    "            curmax = nums.pop(nums.index(max(nums)))\n",
    "            curmin = nums.pop(nums.index(min(nums)))\n",
    "            avg = (curmax + curmin) / 2\n",
    "            if avg not in avgs:\n",
    "                avgs.append(avg)\n",
    "        return len(avgs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    # 排序\n",
    "    def sort_list(nums: List[int]) -> List[int]:\n",
    "        if nums is None:\n",
    "            return nums\n",
    "        \n",
    "        for index in range(0,len(nums)):\n",
    "            pass\n",
    "\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        if nums:\n",
    "            if len(nums) == 2:\n",
    "                return 1\n",
    "            nums = sorted(nums)\n",
    "            array = {}\n",
    "            while len(nums) >1:\n",
    "                min = nums[0]\n",
    "                max = nums[len(nums)-1]\n",
    "                if min == max:\n",
    "                    nums.remove(min)\n",
    "                else:\n",
    "                    nums.remove(min)\n",
    "                    nums.remove(max)\n",
    "                pingjun = (min+max)/2\n",
    "                array[pingjun] = 1\n",
    "            return len(array)\n",
    "        else:\n",
    "            return 0\n",
    "                \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        avg = set()\n",
    "        i = 0\n",
    "        j = len(nums)-1\n",
    "        while i < j:\n",
    "            avg.add((nums[i]+nums[j])/2)\n",
    "            i += 1\n",
    "            j -= 1\n",
    "\n",
    "        return len(avg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        res = set()\n",
    "        left = 0; right = len(nums) - 1\n",
    "        while left < right:\n",
    "            sum = (nums[right] + nums[left]) / 2\n",
    "            res.add(sum)\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        result = []\n",
    "        while nums:\n",
    "            min_num = min(nums)\n",
    "            max_num = max(nums)\n",
    "            result.append((max_num + min_num) / 2)\n",
    "            nums.remove(min_num)\n",
    "            nums.remove(max_num)\n",
    "        return len(set(result))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        nums.sort()\n",
    "        ans=set()\n",
    "        if n<4:\n",
    "            return 1\n",
    "        else:\n",
    "            while len(nums)>=2:\n",
    "                ans.add((nums[0]+nums[-1])/2)\n",
    "                nums=nums[1:len(nums)-1]\n",
    "        return len(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        # n = len(nums)\n",
    "        s = set()\n",
    "        for i in range(int(len(nums)/2)):\n",
    "            s.add(nums[i]+nums[len(nums)-i-1])\n",
    "        return len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        n = len(nums)\n",
    "        left = 0\n",
    "        right = n-1\n",
    "        res = set()\n",
    "        while left < right:\n",
    "            sum_nums = nums[left]+nums[right]\n",
    "            res.add(sum_nums)\n",
    "            left+=1\n",
    "            right-=1\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        l, r = 0, len(nums)-1\n",
    "        hax = set()\n",
    "        while l < r:\n",
    "            hax.add(nums[l]+nums[r])\n",
    "            l += 1\n",
    "            r -= 1\n",
    "        return len(hax)\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        tmp = set()\n",
    "\n",
    "        while len(nums):\n",
    "\n",
    "            min_num = min(nums)\n",
    "            max_num = max(nums)\n",
    "            \n",
    "            avg = (min_num + max_num) / 2\n",
    "\n",
    "            nums.remove(min_num)\n",
    "            nums.remove(max_num)\n",
    "\n",
    "            if avg not in tmp:\n",
    "                tmp.add(avg)\n",
    " \n",
    "        return len(tmp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        ans = set()\n",
    "        nums.sort()\n",
    "        n = len(nums)\n",
    "        for i in range(n // 2):\n",
    "            ans.add((nums[i] + nums[n - 1 - i]) / 2)\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        i = 0\n",
    "        j = len(nums)-1\n",
    "        sets = set()\n",
    "        while i < j:\n",
    "            sets.update({(nums[j]+nums[i])/2.0})\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return len(sets)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        result = set()\n",
    "        nums.sort()\n",
    "        left , right = 0 , n - 1\n",
    "        while left < right:\n",
    "            average = (nums[left] + nums[right]) / 2\n",
    "            result.add(average)\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        return len(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        l, r = 0, len(nums)-1\n",
    "        hax = set()\n",
    "        while l < r:\n",
    "            hax.add(nums[l]+nums[r])\n",
    "            l += 1\n",
    "            r -= 1\n",
    "        return len(hax)\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        left,right = 0,len(nums)-1\n",
    "        hash_s = set()\n",
    "        nums.sort()\n",
    "        while left < right:\n",
    "            average = (nums[left] + nums[right])\n",
    "            hash_s.add(average)\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        return len(hash_s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        n = len(nums)\n",
    "        s = set()\n",
    "        for i in range(n//2):\n",
    "            s.add(nums[i] + nums[-1-i])\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        result = []\n",
    "        while len(nums) >= 2:\n",
    "            maxValue = nums.pop(nums.index(max(nums)))\n",
    "            minValue = nums.pop(nums.index(min(nums)))\n",
    "            result.append((maxValue + minValue) / 2)\n",
    "        \n",
    "        return len(set(result))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        l, r = 0, len(nums)-1\n",
    "        hax = set()\n",
    "        while l < r:\n",
    "            hax.add(nums[l]+nums[r])\n",
    "            l += 1\n",
    "            r -= 1\n",
    "        return len(hax)\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        left,right = 0,len(nums)-1\n",
    "        hash_s = set()\n",
    "        nums.sort()\n",
    "        while left < right:\n",
    "            average = (nums[left] + nums[right])/2\n",
    "            hash_s.add(average)\n",
    "            left += 1\n",
    "            right -= 1\n",
    "        return len(hash_s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        s=set()\n",
    "        l,r=0,len(nums)-1\n",
    "        while l<r:\n",
    "            s.add((nums[l]+nums[r])/2)\n",
    "            l+=1\n",
    "            r-=1\n",
    "        return len(s)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        args=[]\n",
    "        a=len(nums)/2\n",
    "        while nums:\n",
    "            num_max=max(nums)\n",
    "            num_min=min(nums)\n",
    "            arg=(num_max+num_min)/2\n",
    "            nums.remove(num_max)\n",
    "            nums.remove(num_min)\n",
    "            if arg in args:\n",
    "                a-=1\n",
    "            args.append(arg)\n",
    "        return int(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        left=0\n",
    "        right=len(nums)-1\n",
    "        averages={}\n",
    "\n",
    "        while left<right:\n",
    "            average=(nums[left]+nums[right])/2\n",
    "            averages[average]=averages.get(average,0)+1\n",
    "            left+=1\n",
    "            right-=1\n",
    "        \n",
    "        print(averages)\n",
    "        \n",
    "        return len(averages)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        return len(set(nums[i] + nums[-i - 1] for i in range(len(nums) >> 1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums = sorted(nums)\n",
    "        return len(set((nums[i] + nums[len(nums) - i - 1]) / 2 for i in range(len(nums))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        anslist=[]\n",
    "        nums.sort()\n",
    "        for i in range(len(nums)//2):\n",
    "            if (nums[i]+nums[len(nums)-1-i])/2 not in anslist:\n",
    "                anslist.append((nums[i]+nums[len(nums)-1-i])/2)\n",
    "        return len(anslist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "\n",
    "\n",
    "\n",
    "        cnt = collections.Counter(nums)\n",
    "\n",
    "\n",
    "\n",
    "        res = set()\n",
    "\n",
    "\n",
    "        while cnt:\n",
    "\n",
    "\n",
    "            max_ = max(cnt.keys())\n",
    "            cnt[max_] -= 1\n",
    "            if cnt[max_] == 0:\n",
    "                del cnt[max_]\n",
    "            if not cnt:break\n",
    "            min_ = min(cnt.keys())\n",
    "            cnt[min_] -= 1\n",
    "            if cnt[min_] == 0:\n",
    "                del cnt[min_]\n",
    "\n",
    "            res.add((max_ + min_) / 2)\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        seen = set()\n",
    "        i, j = 0, len(nums) - 1\n",
    "        while i < j:\n",
    "            seen.add(nums[i] + nums[j])\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return len(seen)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        q = deque(nums)\n",
    "        n = len(nums)\n",
    "        ans = set()\n",
    "        for _ in range(n//2):\n",
    "            small = q.popleft()\n",
    "            big = q.pop()\n",
    "            ans.add((small+big)/2)\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        v_dict = {}\n",
    "        i = 0\n",
    "        j = len(nums)-1\n",
    "        v_dict[(nums[i]+nums[j])/2] = 1\n",
    "        while i < j:\n",
    "            v = (nums[i]+nums[j])/2\n",
    "            v_dict.setdefault(v, 0)\n",
    "            v_dict[v] += 1\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return len(v_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        avg = set()\n",
    "        while nums != []:\n",
    "            if len(nums) == 1:\n",
    "                avg.add(nums[0])\n",
    "                break\n",
    "            a = nums.pop(0)\n",
    "            b = nums.pop(-1)\n",
    "            avg.add((a+b)/2)\n",
    "\n",
    "        return len(avg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "            nums = sorted(nums)\n",
    "            i = 0\n",
    "            j = len(nums) - 1\n",
    "            count = set()\n",
    "            while i < j:\n",
    "                count.add((nums[i]+nums[j])/2)\n",
    "                i += 1\n",
    "                j -= 1\n",
    "            return len(count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        i,j=0,len(nums)-1\n",
    "        a=set()\n",
    "        while i<j:\n",
    "            a.add(nums[i]+nums[j])\n",
    "            i+=1\n",
    "            j-=1\n",
    "        return len(a)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        n = len(nums)\n",
    "        d = collections.defaultdict(int)\n",
    "        # print(nums)\n",
    "        for i in range(n // 2):\n",
    "            avg = (nums[i] + nums[n - i - 1]) / 2\n",
    "            d[avg] += 1\n",
    "            \n",
    "        return len(d)\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        n =len(nums)\n",
    "        y=0\n",
    "        sum=[]\n",
    "        nums.sort()\n",
    "        while n>1:\n",
    "            S=(nums[y]+nums[n-1])/2\n",
    "            y=y+2\n",
    "            sum.append(S)\n",
    "            n=n-2\n",
    "        sum=set(sum)\n",
    "        d=len(sum)\n",
    "        return d    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        i = 0\n",
    "        j = len(nums) -1\n",
    "        ans_set = set()\n",
    "        while (i < j):\n",
    "\n",
    "            ans_set.add((nums[i]+nums[j])/2)\n",
    "            i +=1\n",
    "            j -=1\n",
    "        \n",
    "        return len(ans_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        left = 0\n",
    "        right = len(nums)-1\n",
    "        res = []\n",
    "        r = 0\n",
    "        while left<=right:\n",
    "            temp = (nums[left] + nums[right])/2\n",
    "            if temp not in res:\n",
    "                res.append(temp)\n",
    "                r = r + 1\n",
    "            left = left + 1\n",
    "            right = right - 1\n",
    "        return r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        cnt=set()\n",
    "        while nums:\n",
    "            cnt.add(nums.pop()+nums.pop(0))\n",
    "        return len(cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        ave = set()\n",
    "        while nums:\n",
    "            a = max(nums)\n",
    "            b = min(nums)\n",
    "            nums.remove(a)\n",
    "            nums.remove(b)\n",
    "            ave.add((a+b)/2)\n",
    "        return len(ave)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 0:\n",
    "            return 0\n",
    "\n",
    "        nums.sort()\n",
    "        averages = set()\n",
    "\n",
    "        while len(nums) != 0:\n",
    "            average = (nums[0] + nums[-1]) / 2\n",
    "            averages.add(average)\n",
    "            del nums[0]\n",
    "            del nums[-1]\n",
    "\n",
    "        return len(averages)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        s = [0 for i in range(0, 201)]\n",
    "        for i in range(0, int(len(nums)/2)):\n",
    "            maxa = max(nums)\n",
    "            mina = min(nums)\n",
    "            nums.remove(maxa)\n",
    "            nums.remove(mina)\n",
    "            s[int(maxa+mina)] += 1\n",
    "        while 0 in s:\n",
    "            s.remove(0)\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        i,j=0,len(nums)-1\n",
    "        ans = set()\n",
    "        while i<j:\n",
    "            avg =( nums[i]+nums[j])/2\n",
    "            ans.add(avg)\n",
    "            i+=1\n",
    "            j-=1\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        l, r = 0, len(nums)-1\n",
    "        ret = set()\n",
    "        while l<r:\n",
    "            ret.add(nums[l]+nums[r])\n",
    "            l += 1\n",
    "            r -= 1\n",
    "        return len(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        start, end = 0, len(nums) - 1\n",
    "        s = set()\n",
    "\n",
    "        while start < end:\n",
    "            agv = (nums[start] + nums[end]) / 2\n",
    "            s.add(agv)\n",
    "            start += 1\n",
    "            end -= 1\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        res=[]\n",
    "        while nums!=[]:\n",
    "            if len(nums)>2:\n",
    "                nums.sort()\n",
    "                res.append((nums[0]+nums[-1])/2)\n",
    "                nums=nums[1:-1]\n",
    "            else:\n",
    "                res.append((nums[0]+nums[-1])/2)\n",
    "                nums=[]\n",
    "        return len(list(set(res)))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        averages = []\n",
    "        while nums:\n",
    "            averages.append((max(nums)+min(nums))/2)\n",
    "            nums.pop(nums.index(max(nums)))\n",
    "            nums.pop(nums.index(min(nums)))\n",
    "        return len(set(averages))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        nums.sort()\n",
    "        n = len(nums)\n",
    "        s = set()\n",
    "        for i in range(int(n/2)):\n",
    "            s.add(nums[i]+nums[n-i-1])\n",
    "        return len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        nums.sort()\n",
    "        s = set()\n",
    "        l, r = 0, n - 1\n",
    "        while l < r:\n",
    "            mid = (nums[l] + nums[r]) / 2\n",
    "            s.add(mid)\n",
    "            l += 1\n",
    "            r -= 1\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        ans_set = set()\n",
    "        while len(nums) > 1:\n",
    "            ans_set.add((max(nums) + min(nums)) / 2)\n",
    "            \n",
    "            nums.remove(max(nums))\n",
    "            nums.remove(min(nums))\n",
    "        return len(ans_set)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "class Solution:\n",
    "    def distinctAverages(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 0:\n",
    "            return 0\n",
    "\n",
    "        nums.sort()\n",
    "        averages = set()\n",
    "        left, right = 0, len(nums) - 1\n",
    "\n",
    "        while left < right:\n",
    "            average = (nums[left] + nums[right]) / 2\n",
    "            averages.add(average)\n",
    "            nums[left] = nums[right] = float('inf')  # 标记元素为无穷大\n",
    "            left += 1\n",
    "            right -= 1\n",
    "\n",
    "        return len(averages)\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
